import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";

import "rxjs/add/observable/of";
import {PageParamsModel} from "../../../model/common/page-params.model";


@Injectable()
export class ClientCompensationProvider {
    data = [
        {
            "applyPremium": "5526.21",// 申请金额
            "acceptTime": "2018-01-01",//受理时间
            "claimsType": "住院医疗", //理赔类型
            "clientId": "1", //客户ID
            "mobilePhone": "",// 电话号码
            "name": "头像2",// 姓名
            "sex": "0", //性别
            "age": "56",
            "vipFlag": "1", //vip等级0-4 ，0为不是vip
            "clientRole": "IO",// 客户角色，投保人1，被保人2，同是投保人和被保人3
        },
        {
            "applyPremium": "5526.21",// 申请金额
            "acceptTime": "2018-01-01",//受理时间
            "claimsType": "住院医疗", //理赔类型
            "clientId": "1", //客户ID
            "mobilePhone": "13134648242",// 电话号码
            "name": "头像2",// 姓名
            "sex": "1", //性别
            "age": "56",
            "vipFlag": "0", //vip等级0-4 ，0为不是vip
            "clientRole": "I",// 客户角色，投保人1，被保人2，同是投保人和被保人3
        },
        {
            "applyPremium": "5526.21",// 申请金额
            "acceptTime": "2018-01-01",//受理时间
            "claimsType": "住院医疗", //理赔类型
            "clientId": "1", //客户ID
            "mobilePhone": "13134648242",// 电话号码
            "name": "头像2",// 姓名
            "sex": "2", //性别
            "age": "56",
            "vipFlag": "4", //vip等级0-4 ，0为不是vip
            "clientRole": "O",// 客户角色，投保人1，被保人2，同是投保人和被保人3
        },
        {
            "applyPremium": "5526.21",// 申请金额
            "acceptTime": "2018-01-01",//受理时间
            "claimsType": "住院医疗", //理赔类型
            "clientId": "1", //客户ID
            "mobilePhone": "",// 电话号码
            "name": "头像2",// 姓名
            "sex": "2", //性别
            "age": "56",
            "vipFlag": "2", //vip等级0-4 ，0为不是vip
            "clientRole": "IO",// 客户角色，投保人1，被保人2，同是投保人和被保人3
        },
        {
            "applyPremium": "5526.21",// 申请金额
            "acceptTime": "2018-01-01",//受理时间
            "claimsType": "住院医疗", //理赔类型
            "clientId": "1", //客户ID
            "mobilePhone": "",// 电话号码
            "name": "头像2",// 姓名
            "sex": "2", //性别
            "age": "56",
            "vipFlag": "2", //vip等级0-4 ，0为不是vip
            "clientRole": "O",// 客户角色，投保人1，被保人2，同是投保人和被保人3
        },

    ];

    constructor(public http: HttpClient) {
    }

    /**
     * 获取理赔
     * @returns {any}
     */
    getClientList(notLoading = 0, pageParams: PageParamsModel,notLoadingNow=0): Observable<any> {

        const params: any = {
            'not-loading': '' + notLoading,
            'not-loading-now':''+ notLoadingNow,
            keyword: pageParams.condition.keyword ? pageParams.condition.keyword : '',
            pageNum: '' + pageParams.pageNum,
            pageSize: '' + pageParams.pageSize
        };
        if (pageParams.orderType) {
            params.orderType = pageParams.orderType;
        }
        return this.http.get(`/party/v1/claimClient`, {
            params
        });
    }

    /**
     * 过滤为空的电话号码
     * @param clientList
     */
    checkMobileNull(clientList) {
        clientList.forEach(client => {
            const mobileList = [];
            if (client.mobilePhone && client.mobilePhone.length) {
                client.mobilePhone.forEach(mobile => {
                    if (mobile && mobile.mobile) {
                        mobileList.push({
                            id: mobile.id,
                            mobile: mobile.mobile
                        });
                    }
                });
            }
            client.mobilePhone = mobileList;
        });
        return clientList;
    }

}
